import GameEvent from '@/game/event'
import useGameStore from '@/store/game';
import getEventListenerList from './event-trigger';
import listenerList from './event-listener';
import { GameEventListener } from '@/types/game/event';
function startGameLoop() {
    const gameStore = useGameStore();
    const loop = GameEvent.createGameEventLoop(gameStore);
    const triggerList = getEventListenerList(gameStore.$state);
    for (const triggerName in triggerList) {
        loop.addEventTrigger(triggerList[triggerName]);
    }
    for (const eventName in listenerList) {
        listenerList[eventName].forEach((listener: GameEventListener) => {
            loop.registerEventListener(eventName, listener);
        })
    }
    gameStore.$state.gameStarted = true;
    loop.start();
    return {
        loop,
        triggerList,
        listenerList
    }
}
export default {
    startGameLoop
}